Return address optimisation for a dynamic code translator

ABSTRACT

A dynamic code translator with isoblocking uses a return trampoline having branch instructions conditioned on different isostates to optimize return address translation, by allowing the hardware to predict that the address of a future return will be the address of trampoline. An IP relative call is inserted into translated code to write the trampoline address to a target link register and a target return address stack used by the native machine to predict return addresses. If a computed subject return address matches a subject return address register value, the current isostate of the isoblock is written to an isostate register. The isostate value in the isostate register is then used to select the branch instruction in the trampoline for the true subject return address. Sufficient code area in the trampoline instruction set can be reserved for a number of compare/branch pairs which is equal to the number of available isostates.

CROSS-REFERENCE TO RELATED APPLICATION

This application is a continuation of copending U.S. patent applicationSer. No. 13/186,831 filed Jul. 20, 2011.

BACKGROUND OF THE INVENTION

1. Field of the Invention

The present invention generally relates to computer systems andemulation, and more particularly to dynamic binary translators which useisoblocks to cache translated code.

2. Description of the Related Art

It is often useful to run a computer program designed for one computersystem having a particular processor architecture and operating system(OS) on another computer system having a different processorarchitecture and/or OS. For example, it is desirable to allow newcomputer systems to run legacy programs without having to redesign thoseprograms. It takes a significant amount of time (and thus cost) to portan older software application to a new platform. If there is a change inthe hardware instruction set, then the application must be recompiled.If there is a change in the OS, then applications must be rewritten touse the new OS calls. Significant changes could be required in thesource code just to get the application to do what it did before,without adding any new functionality. In many cases, the cost to port anapplication may be as much as 40% of the original development cost. Ifthe application was obtained from an outside vendor then, even if thesource is available, the understanding of the application's architectureand logic are not necessarily available to the programmers who will beporting the application. If the source for the original application waslost, then porting is not even possible. Reverse engineering or startingdevelopment from scratch are also expensive alternatives.

Computer emulation provides a means for a native (target) computersystem to execute programs designed for otherwise incompatible systems.An emulator is hardware and/or software that duplicates the functions ofthe original (subject) computer system in the target computer system, sothat the behavior of the target system closely resembles the behavior ofthe subject system. One method of computer emulation known as binarytranslation takes a sequence of executable code (a set of binaryinstructions) from the subject environment and translates it into asequence of executable code adapted for the target environment. The codesequence may be a basic block, i.e., a portion of the code with certaindesirable properties that make it highly amenable to analysis. Compilersusually decompose programs into their basic blocks as a first step inthe analysis process. Basic blocks form the vertices or nodes in acontrol flow graph. The code in a basic block typically has one entrypoint, meaning no code within it is the destination of a jumpinstruction anywhere in the program, and one exit point, meaning onlythe last instruction can cause the program to begin executing code in adifferent basic block. Under these circumstances, whenever the firstinstruction in a basic block is executed, the rest of the instructionsare necessarily executed exactly once, in order.

SUMMARY OF THE INVENTION

The present invention relates to a method of optimizing return addresstranslation in a dynamic code translator, by receiving a function callfrom subject code designed for a first machine having a first hardwareenvironment, compiling an isoblock including at least target code andcompatibility information wherein the target code is designed for asecond machine having a second hardware environment which is differentfrom the first hardware environment and the target code includes asubfunction corresponding to the function call, planting in the targetcode a trampoline instruction set having a plurality of branchinstructions which return a true subject return address conditioned onan isostate of the isoblock stored in an isostate register, andinserting in the target code instructions which write an address of thetrampoline instruction set to a target return address stack of thesecond machine, instructions which write an address from the subjectcode directly following the function call to a subject return addressregister, and instructions which write the isostate of the isoblock tothe isostate register when a computed subject return address matches anentry in the subject return address register. The instructions whichwrite the address of the trampoline instruction set to the target returnaddress stack include an IP relative target call that also writes theaddress of the trampoline instruction set to a target link register, andinstructions are further inserted which save an existing target returnaddress from the target link register and an existing subject returnaddress from a subject return address register in a translator returnaddress stack, prior to writing the address of the trampolineinstruction set to the target link register. The isostate register canbe a non-fix-mapped target register. Sufficient code area in thetrampoline instruction set can be reserved for a number ofcompare/branch pairs which is equal to the number of availableisostates. The trampoline instruction set can include recovery code tofind a successor block if the isostate in the isostate register does notmatch an isostate for any of the branch instructions.

The above as well as additional features and advantages of the presentinvention will become apparent in the following detailed writtendescription.

BRIEF DESCRIPTION OF THE DRAWINGS

The present invention may be better understood, and its numerousobjects, features, and advantages made apparent to those skilled in theart by referencing the accompanying drawings.

FIG. 1 is a block diagram of a conventional dynamic code translationsystem which uses isoblocks stored in a cache;

FIG. 2 is a block diagram of a computer system programmed to carry outdynamic code translation in accordance with one implementation of thepresent invention;

FIG. 3 is a pictorial representation of a target code sequence createdby the translator in accordance with one implementation of the presentinvention, and its interaction with various registers and stacks;

FIG. 4 is a chart illustrating the logical flow for a dynamic binarytranslation process in accordance with one implementation of the presentinvention wherein three different procedures can be used to plantinstructions in the target code sequence during execution of the subjectprogram; and

FIG. 5 is a chart illustrating the logical flow for execution of thetranslated code, including planted instructions, by a target machine inaccordance with one implementation of the present invention.

The use of the same reference symbols in different drawings indicatessimilar or identical items.

DESCRIPTION OF THE PREFERRED EMBODIMENT(S)

Dynamic code translation, also referred to as dynamic binary translation(DBT), is a form of binary translation which takes place in real-time,that is, as an application is executing on the target machine. DBTtranslates a basic block and caches the resulting sequence. Code is onlytranslated as it is discovered and when possible, and branchinstructions are made to point to already translated and saved code(memoization). DBT differs from simple emulation by eliminating theemulator's main read-decode-execute loop (a major performancebottleneck), but incurs large overhead during translation time. Thisoverhead is hopefully amortized as translated code sequences areexecuted multiple times during continued program execution. QuickTransitwas a cross-platform virtualization program developed by TransitiveCorp. which utilized DBT. It allowed software compiled for one specificprocessor and operating system combination to be executed on a differentsystem architecture without requiring changes to source code or binarycode. QuickTransit was an extension of the Dynamite technology developedat the University of Manchester. One QuickTransit combination currentlyavailable is the PowerVM product from International Business MachinesCorp. That product is a virtualization platform for UNIX, Linux and IBMi clients, and thus allows information technology professionals toreduce IT costs by consolidating diverse workloads onto a singleplatform.

A simplified version of dynamic code translation is illustrated inFIG. 1. The emulation system includes a subject environment 2 which mayor may not have its own OS, a target environment 3 which also may or maynot have its own OS, and the dynamic code translator 4 which acts as acommunications agent between the two environments. Based on the presenceof operating systems for the subject and target environments, thetranslator may be configured as “above”, “below”, or “in-between”operating systems. Other configurations are possible depending upon thehardware systems involved.

In carrying out the translation, dynamic code translator 4 uses aplurality of isoblocks 5 which are stored in a software cache 6. Anisoblock is a basic block with additional compatibility information. Thecompatibility information is different for each subject architecture totake into account different architectural features. An isoblock caninclude translated code, a subject address, a target code pointer,translation hints, entry conditions, exit conditions, a profilingmetric, a list of predecessor blocks, a list of successor blocks, and anentry register map. If execution reaches a basic block which has alreadybeen translated but the previous translation's entry conditions differfrom the current working conditions (i.e., the exit conditions of theprevious block), then the basic block must be translated again based onthe current working conditions. The result is that the same subject codebasic block can be represented by multiple target code translations(isoblocks).

One problem that can arise with DBT using isoblocking technology relatesto the address of a return from a function call. In computerprogramming, a return statement causes execution to leave the currentsubroutine and resume at the point in the code immediately after wherethe subroutine was called, known as its return address. The returnaddress is usually saved on the process's call stack as part of theoperation of making the subroutine call. Modern CPU architecturescontain hardware that is very effective at predicting the addresses ofreturns from function calls, making execution of these returns veryefficient. For example, on a modern POWER architecture during the callthe hardware pushes the address to be returned to onto a hardware stack(last-in, first-out). This address will be the address of theinstruction immediately following the call. When a return isencountered, the hardware pops the top entry off this stack, andpredicts this value will be the address to be returned to.

A core assumption of this hardware mechanism is that there is a singleaddress to be returned to, and that this address is usually theinstruction directly after the call. When dynamically translating asubject program using DBT with isoblocking technology, these assumptionsare no longer valid. There is no assurance that the subject program willnot have modified its record of the return address, so it is possiblethat the return should go to a different location than expected.Furthermore, with isoblocking, there are likely to be multiple differenttranslations of the subject address to be returned to as explainedabove. Even if the hardware could be sure of the correct return address,there might be multiple blocks that start with that address. This latterissue prevents a naive translator from constructing an emulation of asubject call-return stack, since the required information is only knownat runtime, very close to the point where it is used, effectivelycreating an indirect branch. It is very difficult for target hardware toeffectively predict the addresses of indirect branches, and notsurprisingly such a solution can perform very poorly.

In light of the foregoing, it would be desirable to devise an improvedmethod of dynamic code translation which could more efficiently providereturn addresses. It would be particularly advantageous if the methodcould allows native address prediction hardware to function moreeffectively, thereby improving performance.

With reference now to the figures, and in particular with reference toFIG. 2, there is depicted one embodiment 10 of a computer system inwhich the present invention may be implemented to carry out the dynamicbinary translation of a subject software application. Computer system 10is a symmetric multiprocessor (SMP) system having a plurality ofprocessors 12 a, 12 b connected to a system bus 14. System bus 14 isfurther connected to a combined memory controller/host bridge (MC/HB) 16which provides an interface to system memory 18. System memory 18 may bea local memory device or alternatively may include a plurality ofdistributed memory devices, preferably dynamic random-access memory(DRAM). There may be additional structures in the memory hierarchy whichare not depicted, such as on-board (L1) and second-level (L2) orthird-level (L3) caches.

MC/HB 16 also has an interface to peripheral component interconnect(PCI) Express links 20 a, 20 b, 20 c. Each PCI Express (PCIe) link 20 a,20 b is connected to a respective PCIe adaptor 22 a, 22 b, and each PCIeadaptor 22 a, 22 b is connected to a respective input/output (I/O)device 24 a, 24 b. MC/HB 16 may additionally have an interface to an I/Obus 26 which is connected to a switch (I/O fabric) 28. Switch 28provides a fan-out for the I/O bus to a plurality of PCI links 20 d, 20e, 20 f. These PCI links are connected to more PCIe adaptors 22 c, 22 d,22 e which in turn support more I/O devices 24 c, 24 d, 24 e. The I/Odevices may include, without limitation, a keyboard, a graphicalpointing device (mouse), a microphone, a display device, speakers, apermanent storage device (hard disk drive) or an array of such storagedevices, an optical disk drive, and a network card. Each PCIe adaptorprovides an interface between the PCI link and the respective I/Odevice. MC/HB 16 provides a low latency path through which processors 12a, 12 b may access PCI devices mapped anywhere within bus memory or I/Oaddress spaces. MC/HB 16 further provides a high bandwidth path to allowthe PCI devices to access memory 18. Switch 28 may provide peer-to-peercommunications between different endpoints and this data traffic doesnot need to be forwarded to MC/HB 16 if it does not involvecache-coherent memory transfers. Switch 28 is shown as a separatelogical component but it could be integrated into MC/HB 16.

In this embodiment, PCI link 20 c connects MC/HB 16 to a serviceprocessor interface 30 to allow communications between I/O device 24 aand a service processor 32. Service processor 32 is connected toprocessors 12 a, 12 b via a JTAG interface 34, and uses an attentionline 36 which interrupts the operation of processors 12 a, 12 b. Serviceprocessor 32 may have its own local memory 38, and is connected toread-only memory (ROM) 40 which stores various program instructions forsystem startup. Service processor 32 may also have access to a hardwareoperator panel 42 to provide system status and diagnostic information.

In alternative embodiments computer system 10 may include modificationsof these hardware components or their interconnections, or additionalcomponents, so the depicted example should not be construed as implyingany architectural limitations with respect to the present invention. Theinvention may further be implemented in an equivalent cloud computingnetwork.

When computer system 10 is initially powered up, service processor 32uses JTAG interface 34 to interrogate the system (host) processors 12 a,12 b and MC/HB 16. After completing the interrogation, service processor32 acquires an inventory and topology for computer system 10. Serviceprocessor 32 then executes various tests such as built-in-self-tests(BISTs), basic assurance tests (BATs), and memory tests on thecomponents of computer system 10. Any error information for failuresdetected during the testing is reported by service processor 32 tooperator panel 42. If a valid configuration of system resources is stillpossible after taking out any components found to be faulty during thetesting then computer system 10 is allowed to proceed. Executable codeis loaded into memory 18 and service processor 32 releases hostprocessors 12 a, 12 b for execution of the program code, e.g., anoperating system (OS) which is used to launch applications, and inparticular the dynamic code translator of the present invention whichmay reside on the hard disk drive, a DVD, or other computer readablestorage medium. While host processors 12 a, 12 b are executing programcode, service processor 32 may enter a mode of monitoring and reportingany operating parameters or errors, such as the cooling fan speed andoperation, thermal sensors, power supply regulators, and recoverable andnon-recoverable errors reported by any of processors 12 a, 12 b, memory18, and MC/HB 16. Service processor 32 may take further action based onthe type of errors or defined thresholds.

As will be appreciated by one skilled in the art, the present inventionmay be embodied as a system, method or computer program product.Accordingly, the present invention may take the form of an entirelyhardware embodiment, an entirely software embodiment (includingfirmware, resident software, micro-code, etc.) or an embodimentcombining software and hardware aspects that may all generally bereferred to herein as a “circuit,” “module” or “system.” Furthermore,the present invention may take the form of a computer program productembodied in any tangible medium of expression having computer usableprogram code embodied in the medium.

Any combination of one or more computer usable or computer readablemedia may be utilized. The computer-usable or computer-readable mediummay be, for example but not limited to, an electronic, magnetic,optical, electromagnetic, infrared, or semiconductor system, apparatus,device, or propagation medium. More specific examples (a non-exhaustivelist) of the computer-readable medium would include the following: anelectrical connection having one or more wires, a portable computerdiskette, a hard disk, a random access memory (RAM), a read-only memory(ROM), an erasable programmable read-only memory (EPROM or Flashmemory), an optical fiber, a portable compact disc read-only memory(CDROM), an optical storage device, a transmission media such as thosesupporting the Internet or an intranet, or a magnetic storage device.The computer-usable or computer-readable medium could even be paper oranother suitable medium upon which the program is printed, as theprogram can be electronically captured, via, for instance, opticalscanning of the paper or other medium, then compiled, interpreted, orotherwise processed in a suitable manner, if necessary, and then storedin a computer memory. In the context of this invention, acomputer-usable or computer-readable medium may be any medium that cancontain, store, communicate, propagate, or transport the program for useby or in connection with the instruction execution system, apparatus, ordevice. The computer-usable medium may include a propagated data signalwith the computer-usable program code embodied therewith, either inbaseband or as part of a carrier wave. The computer usable program codemay be transmitted using any appropriate medium, including but notlimited to wireless, wireline, optical fiber cable, RF, etc.

Computer program code for carrying out operations of the presentinvention may be written in any combination of one or more programminglanguages, including an object oriented programming language such asJava, Smalltalk, C++ or the like and conventional procedural programminglanguages, written for a variety of platforms such as an AIX environmentor operating systems such as Windows 7 or Linux. The program code mayexecute entirely on the user's computer, partly on the user's computer,as a stand-alone software package, partly on the user's computer andpartly on a remote computer or entirely on the remote computer orserver. In the latter scenario, the remote computer may be connected tothe user's computer through any type of network, including a local areanetwork (LAN) or a wide area network (WAN), or the connection may bemade to an external computer (for example, through the Internet using anInternet Service Provider).

The present invention is described below with reference to flowchartillustrations and/or block diagrams of methods, apparatus (systems) andcomputer program products according to embodiments of the invention. Itwill be understood that each block of the flowchart illustrations and/orblock diagrams, and combinations of blocks in the flowchartillustrations and/or block diagrams, can be implemented by computerprogram instructions. These computer program instructions may beprovided to a processor of a general purpose computer, special purposecomputer, or other programmable data processing apparatus to produce amachine, such that the instructions, which execute via the processor ofthe computer or other programmable data processing apparatus, createmeans for implementing the functions/acts specified in the flowchartand/or block diagram block or blocks.

These computer program instructions may also be stored in acomputer-readable medium that can direct a computer or otherprogrammable data processing apparatus to function in a particularmanner, such that the instructions stored in the computer-readablemedium produce an article of manufacture including instruction meanswhich implement the function/act specified in the flowchart and/or blockdiagram block or blocks. Such storage media excludes transitory media.

The computer program instructions may further be loaded onto a computeror other programmable data processing apparatus to cause a series ofoperational steps to be performed on the computer or other programmableapparatus to produce a computer implemented process such that theinstructions which execute on the computer or other programmableapparatus provide processes for implementing the functions/actsspecified in the flowchart and/or block diagram block or blocks.

The flowchart and block diagrams in the figures illustrate thearchitecture, functionality, and operation of possible implementationsof systems, methods and computer program products according to variousembodiments of the present invention. In this regard, each block in theflowchart or block diagrams may represent a module, segment, or portionof code, which comprises one or more executable instructions forimplementing the specified logical function(s). In some alternativeimplementations, the functions noted in the block may occur out of theorder noted in the figures. For example, two blocks shown in successionmay, in fact, be executed substantially concurrently, or the blocks maysometimes be executed in the reverse order, depending upon thefunctionality involved. Unless otherwise explicitly indicated, eachblock of the block diagrams and/or flowchart illustration, andcombinations of blocks in the block diagrams and/or flowchartillustration, can be implemented by special purpose hardware-basedsystems that perform the specified functions or acts, or combinations ofspecial purpose hardware and computer instructions.

Computer system 10 carries out program instructions for a dynamic codetranslation process that uses novel isostate tracking to optimize returnaddresses. Accordingly, a program embodying the invention may includeconventional aspects of various DBT tools, and these details will becomeapparent to those skilled in the art upon reference to this disclosure.

There are three regions of subject code that are of particular interestto the present invention: the subject call which passes control into asubfunction; the subject return at the end of a subfunction which issupposed to return back to the address directly following the call; andthe actual address directly after the call (the return destination).Different pieces of code can be planted in the target code sequence(i.e., the translated code executed by the target machine) as each ofthese regions is encountered and translated. FIG. 3 illustrates anexample of such a target code sequence 50 constructed in accordance withthe present invention as part of a dynamic binary translation process.During the translation of a subject call, a native call instruction 52can be planted over a small area of code referred to as a trampoline 54.This allows the hardware to predict that the address of a future returnwill be the address of trampoline 54. This address, along with thesubject return address (which is known statically at translate time) canadditionally be saved on a software stack, referred to herein as thetranslator return address stack 56. Each entry in that stack thusconstitutes a subject address-target address pair the program isexpected to return to. Translator return address stack 56 is last-in,first-out (LIFO). The invention further uses a target link register 58to store the current target address, and a subject return addressregister 60 for recording the most recent subject address thatcorresponds to the target address currently in the target link register.

At the point a subject call is first encountered, save current code 62can be planted in the translated code to take the existing values fromtarget link register 58 and subject return address register 60, and savethem in translator return address stack 56. The native call instruction52 is then planted to move execution forward a small number of targetinstructions, over trampoline 54. Call 52 is an unconditional,instruction pointer (IP) relative target call. IP relative addressinguses a displacement value and an instruction pointer as addressoperands, as opposed to displacement-only addressing. In this case thedisplacement is +4 for the trampoline address. This call has twoimplicit side-effects: the address of the return trampoline is placed intarget link register 58, and the same address is additionally pushedonto the head of a LIFO target return address stack 64. Target returnaddress stack 64 is a hardware feature used by the target machine topredict the destination of future return instructions, and isarchitecture specific. Target return address stack 64 allows thearchitecture to start fetching instructions from the return site andthereby avoid pipeline stalls. The present invention takes advantage ofthis type of hardware optimization by using the IP relative calldirectly before the trampoline, which causes the target hardware topredict the return to that trampoline and so perform efficiently. Thetranslator may further utilize a subject stack which is an emulation ofthe true subject machine return address stack. In most architectures,each frame on this stack will contain a true subject return address,which might be manipulated by the subject program itself.

Trampoline 54 restores target link register 58 and subject returnaddress register 60 by taking the values from translator return addressstack 56. Trampoline 54 is thereafter populated with conditionalrelative branches for each known translated isoblock for this subjectaddress. Each branch is conditioned on an integer value representing anentry isostate of each block, encoded during translation as describedfurther below. The static isostate values in trampoline 54 can becompared to an isostate value in a dynamic register 66 to determine theappropriate address for the corresponding block. Control then jumps tothat block. Any block could potentially start at the subject address ofone or more existing trampolines. Trampoline 54 can reserve code areafor as many compare/branch pairs as there are possible isostateencodings (initially filled with no-ops). Trampoline 54 can also includerecovery code to find the next block in case no matching isostate isfound (such as the QuickTransit targetCodeAddComputedSuccessor command).

Immediately after the call (in the code region directly after the end oftrampoline 54), update code 68 can be planted to update subject returnaddress register 60 to contain the subject address directly after thecall. Control then passes to the target subfunction 70 corresponding tothe subject function call.

When translating a return, comparison code 72 is planted in target codesequence 50 to compare the saved subject return address from subjectreturn address register 60 with the computed subject return address(often a value on the subject stack, depending on the subjectarchitecture). If they are equal, the exit isostate of the return blockis written into isostate register 66, and control returns to the addressof trampoline 54. Since the address of trampoline 54 is expected by thehardware prediction logic, this return will be very low cost. A targetreturn instruction 74 is then planted to jump to the address in targetlink register 58 (which will return control back to trampoline 54directly following the previously executed call). If the comparison doesnot match, the translator plants restore code 76 for traversing acomputed jump as normal. In order to keep translator return addressstack 56 in synchronization, a pair of values are taken off it,restoring them to target link register 58 and subject return addressregister 60.

Isostate register 66 can be inside the target code but should remainoutside of target code for any specific block. It can for example be anon-fix-mapped target register (software). In the preferredimplementation of the invention there are a relatively small number ofisostate encodings, for example, 16. The invention is able toaccommodate such a small number because of certain likely behaviors ofisostates. Many isostate flags are extremely static, such as whether afloating point unit is active, or whether the translator is currentlyexecuting 16-bit code. For a given run of an application, they willeither be asserted or not, and this state will almost never change. Mostother isostate flags are extremely dynamic. A few isostate flags, suchas compare flags, change so often that they are overwritten by almostevery block, without the previous value being used. Therefore, the stateof these flags from a previous block is irrelevant as they will never beused. Very few flags land in between these two extremes, so the resultis only a few different isostates at runtime. The invention can furtheruse the concept of a “don't care” state—a mask of isostate flags thatare overwritten within the block without their previous values beingused. If the values of the extremely dynamic flags are masked out, and aglobal list of distinct masked values is maintained, the translator cansuccessively encode each isostate as it is encountered with a valuebetween 0 and n−1, where n is the number of isostates available. In theunlikely event that this table is filled, the optimization is no longerapplied to blocks with different masked isostates. This approach allowsthe translator to cover almost all blocks whilst keeping the number ofdistinct isostate encodings very small.

The present invention may be further understood with reference to thechart of FIG. 4 which illustrates the logical flow for a dynamic binarytranslation process 80 in accordance with one implementation of thepresent invention wherein three different procedures can be used toplant instructions in the target code sequence during execution of thesubject program. The process begins when the translator receives asubjection function call 82 which is to be executed in the nativeenvironment. The translator creates an isoblock for the function call84. Different code can then be translated depending on the order ofexecution in the subject program. If a subject call occurs 86, thetranslator will plant the save current code 88, plant the IP relativecall 90, plant the return trampoline 92 including population of abranch, and plant the subject return address update 94. If a subjectreturn occurs 96 (presumably the subfunction has been translated beforethe return), the translator will plant the compare code 98, plant thereturn code 100, and plant the restore code 102. For any block whosesubject address matches the subject address of any trampoline 104, abranch entry is inserted in the trampoline for the current isostate 106.This entry will cause execution to jump to the target code for thisblock when the isostate register matches this isostate. Once created,the isoblock can be cached for future repeated use.

FIG. 5 illustrates a chart of the logical flow for an execution process110 of the translated code, including planted instructions, by a targetmachine according to the foregoing implementation. The process beginswhen the target machine receives the translated code 114. Currententries in the target link register and subject return address registerare saved to the translator return address stack 114. In response to theIP relative call, the trampoline address is written to the target linkregister and target return address stack 116. The subject return addressregister is then updated 118 and the subfunction is executed 120. Acheck is made to see if the computed return address matches the value inthe subject return address register 122. If the values do not match, thetarget machine traverses a computed jump according to conventional rules124. If the values match, the target machine writes the exit isostate tothe isostate register 126 and returns to the trampoline 128. The targetlink register and subject return address register are restored using thetranslator return address stack 130. The target code then checks thevalue in the isostate register against the isostate of an existingtranslated block 132. If the isostate register does not match anyprevious block, the target machine again traverses a computed jumpaccording to conventional rules 124. If the isostate register does matchan early block, the target machine jumps to the target code for theexisting block 134.

By separating the identification of the subject return address and theisoblock state, the present invention allows the native addressprediction hardware to function effectively, thereby improvingperformance. A translator constructed in accordance with the presentinvention replaces a very slow indirect branch with a quick return,compare, and IP relative branch, which are much more efficient.

Although the invention has been described with reference to specificembodiments, this description is not meant to be construed in a limitingsense. Various modifications of the disclosed embodiments, as well asalternative embodiments of the invention, will become apparent topersons skilled in the art upon reference to the description of theinvention. It is therefore contemplated that such modifications can bemade without departing from the spirit or scope of the present inventionas defined in the appended claims.

What is claimed is:
 1. A method of optimizing return address translationin a dynamic code translator comprising: receiving a function call fromsubject code designed for a first machine having a first hardwareenvironment; compiling an isoblock including at least target code andcompatibility information wherein the target code is designed for asecond machine having a second hardware environment which is differentfrom the first hardware environment and the target code includes asubfunction corresponding to the function call; planting in the targetcode a trampoline instruction set having a plurality of branchinstructions which return a true subject return address conditioned onan isostate of the isoblock stored in an isostate register; andinserting in the target code instructions which write an address of thetrampoline instruction set to a target return address stack of thesecond machine, instructions which write an address from the subjectcode directly following the function call to a subject return addressregister, and instructions which write the isostate of the isoblock tothe isostate register when a computed subject return address matches anentry in the subject return address register.
 2. The method of claim 1wherein the instructions which write the address of the trampolineinstruction set to the target return address stack include an IPrelative target call.
 3. The method of claim 2 wherein: the IP relativetarget call also writes the address of the trampoline instruction set toa target link register; and said inserting further inserts instructionswhich save an existing target return address from the target linkregister and an existing subject return address from a subject returnaddress register in a translator return address stack, prior to writingthe address of the trampoline instruction set to the target linkregister.
 4. The method of claim 1 wherein the isostate register is anon-fix-mapped target register.
 5. The method of claim 1 wherein thetrampoline instruction set further includes recovery code to find asuccessor block when the isostate in the isostate register does notmatch an isostate for any of the branch instructions.
 6. The method ofclaim 1 wherein said planting reserves code area in the trampolineinstruction set for a number of compare/branch pairs which is equal to anumber of available isostates.
 7. The method of claim 1, furthercomprising passing the target code including the inserted instructionsand trampoline instruction set to the second machine for execution.
 8. Acomputer system comprising: a first hardware environment including oneor more processors which process program instructions and a memorydevice connected to said one or more processors; and a dynamic codetranslator residing in said memory device which optimizes return addresstranslation by receiving a function call from subject code designed fora different computer system having a second hardware environment whichis different from the first hardware environment, compiling an isoblockincluding at least target code and compatibility information wherein thetarget code is designed for the first hardware environment and includesa subfunction corresponding to the function call, planting in the targetcode a trampoline instruction set having a plurality of branchinstructions which return a true subject return address conditioned onan isostate of the isoblock stored in an isostate register, andinserting in the target code instructions which write an address of thetrampoline instruction set to a target return address stack of thesecond machine, instructions which write an address from the subjectcode directly following the function call to a subject return addressregister, and instructions which write the isostate of the isoblock tothe isostate register when a computed subject return address matches anentry in the subject return address register.
 9. The computer system ofclaim 8 wherein the instructions which write the address of thetrampoline instruction set to the target return address stack include anIP relative target call.
 10. The computer system of claim 9 wherein: theIP relative target call also writes the address of the trampolineinstruction set to a target link register; and said dynamic codetranslator further inserts instructions in the target code which save anexisting target return address from the target link register and anexisting subject return address from a subject return address registerin a translator return address stack, prior to writing the address ofthe trampoline instruction set to the target link register.
 11. Thecomputer system of claim 8 wherein the isostate register is anon-fix-mapped target register.
 12. The computer system of claim 8wherein the trampoline instruction set further includes recovery code tofind a successor block when the isostate in the isostate register doesnot match an isostate for any of the branch instructions.
 13. Thecomputer system of claim 8 wherein said dynamic code translator furtherreserves code area in the trampoline instruction set for a number ofcompare/branch pairs which is equal to a number of available isostates.14. The computer system of claim 8 wherein said dynamic code translatorfurther passes the target code including the inserted instructions andtrampoline instruction set to the first hardware environment forexecution.
 15. A computer program product comprising: acomputer-readable storage medium; and a dynamic code translator residingin said storage medium which optimizes return address translation byreceiving a function call from subject code designed for a firstcomputer system having a first hardware environment, compiling anisoblock including at least target code and compatibility informationwherein the target code is designed for a second computer system havinga second hardware environment which is different from the first hardwareenvironment and the target code includes a subfunction corresponding tothe function call, planting in the target code a trampoline instructionset having a plurality of branch instructions which return a truesubject return address conditioned on an isostate of the isoblock storedin an isostate register, and inserting in the target code instructionswhich write an address of the trampoline instruction set to a targetreturn address stack of the second computer system, instructions whichwrite an address from the subject code directly following the functioncall to a subject return address register, and instructions which writethe isostate of the isoblock to the isostate register when a computedsubject return address matches an entry in the subject return addressregister.
 16. The computer program product of claim 15 wherein theinstructions which write the address of the trampoline instruction setto the target return address stack include an IP relative target call.17. The computer program product of claim 16 wherein: the IP relativetarget call also writes the address of the trampoline instruction set toa target link register; and said dynamic code translator further insertsinstructions in the target code which save an existing target returnaddress from the target link register and an existing subject returnaddress from a subject return address register in a translator returnaddress stack, prior to writing the address of the trampolineinstruction set to the target link register.
 18. The computer programproduct of claim 15 wherein the isostate register is a non-fix-mappedtarget register.
 19. The computer program product of claim 15 whereinthe trampoline instruction set further includes recovery code to find asuccessor block when the isostate in the isostate register does notmatch an isostate for any of the branch instructions.
 20. The computerprogram product of claim 15 wherein said dynamic code translator furtherreserves code area in the trampoline instruction set for a number ofcompare/branch pairs which is equal to a number of available isostates.21. The computer program product of claim 15 wherein said dynamic codetranslator further passes the target code including the insertedinstructions and trampoline instruction set to the second computersystem for execution.